﻿using System;
using Model;
using Resources;
using Service;

public partial class SoftwareAdd : System.Web.UI.Page
{

    readonly ReferenceDataService _ReferenceDataService = new ReferenceDataService();
    private readonly EquipmentSoftware _software = new EquipmentSoftware();
   

    protected void Page_Load(object sender, EventArgs e)
    {
       

    }
    protected void bntValidate_Click(object sender, EventArgs e)
    {
        _software.SoftwareId = 0;
        if (dlGroupeSoftware.SelectedIndex == 0)
        {
            lblRequiredGroupeSoftware.Visible = true;
            return;
        }
        if (txtsoftware.Text == "")
        {
            lblRequiredSoftware.Visible = true;
            return;
        }

        _software.GroupeSoftwareId = (Int32.Parse(dlGroupeSoftware.SelectedValue));
        _software.SoftwareLabel = txtsoftware.Text;
        _software.Description = txtdescription.Text;
        _software.Version = txtversion.Text;
         int i = 0;
         if (!string.IsNullOrEmpty(txtNbLisence.Text))
         {
             if (int.TryParse(txtNbLisence.Text, out i))
             {
                 _software.NbLisence = i;
             }
             else
             {
                 lblLisenceRequire.Visible = true;
                 return;
             }
         }
        _ReferenceDataService.SaveSoftware(_software);
        lblRequiredGroupeSoftware.Visible = false;
        lblRequiredSoftware.Visible = false;
        lblLisenceRequire.Visible = false;
        lblMessageValidate.Text = Resource.MessageValidate; 
        Session["LoadFirstTab"] = "true";
        ClearControlAdd();

    }
    private void ClearControlAdd()
    {
        txtdescription.Text = "";
        txtsoftware.Text = "";
        txtversion.Text = "";
        txtNbLisence.Text = ""; 
        dlGroupeSoftware.SelectedIndex =-1;
       
    }
    protected void bntCancel_Click(object sender, EventArgs e)
    {
        ClearControlAdd();
        lblMessageValidate.Text = ""; 
    }
    
}
